import axios from 'axios'

const request = axios.create({
  baseURL: 'http://localhost:8000',
  timeout: 5000
})
request.interceptors.response.use(
  response => {
    if (response.status === 200 && response.data) {
      return Promise.resolve(response.data)
    } else {
      return Promise.reject(new Error('请求失败'))
    }
  },
  error => {
    return Promise.reject(error)
  }
)

export function wordCloud () {
  return request({
    url: '/rest/wordcloud',
    method: 'get'
  })
}

export function map () {
  return request({
    url: '/rest/map',
    method: 'get'
  })
}

export function liquidFill () {
  return request({
    url: '/rest/liquidFill',
    method: 'get'
  })
}

export function totalSales () {
  return request({
    url: '/rest/totalSales',
    method: 'get'
  })
}

export function totalOrder () {
  return request({
    url: '/rest/totalOrder',
    method: 'get'
  })
}

export function todayUsers () {
  return request({
    url: '/rest/todayUsers',
    method: 'get'
  })
}

export function totalUsers () {
  return request({
    url: '/rest/totalUsers',
    method: 'get'
  })
}

export function yearSales (index) {
  return request({
    url: '/rest/yearSales',
    method: 'get',
    params: { index }
  })
}

export function rankData (index) {
  return request({
    url: '/rest/rankData',
    method: 'get',
    params: { index }
  })
}

export function search () {
  return request({
    url: '/rest/search',
    method: 'get'
  })
}

export function searchWord (pageNumber, pageSize) {
  return request({
    url: '/rest/searchWord',
    method: 'get',
    params: {
      pageNumber,
      pageSize
    }
  })
}

export function pieData () {
  return request({
    url: '/rest/pieData',
    method: 'get'
  })
}
